<template>
  <div>
    <StoreChoice
      ref="StoreChoice"
      :isReset="true"
      :current="[]"
      :multipleChoice="false"
      @listenToStoreSelect="getSelectStoreValue"
      :statusFilter="false"
      :hasTotal="true"
      :stylewidth="true"
    />

    <customHeader middleTitle="商家信息"></customHeader>
    <div class="management">
      <div class="stepping" v-if="data.shopType">
        <div class="p1">
          <p>商户类型</p>
        </div>
        <div class="p2">
          <p>
            {{
              data.shopType == "01"
                ? "自然人"
                : data.shopType == "02"
                ? "个体工商户"
                : "企业商户"
            }}
          </p>
        </div>
      </div>
      <div class="stepping" v-if="data.companyName">
        <div class="p1">
          <p>公司全称</p>
        </div>
        <div class="p2">
          <p>{{ data.companyName }}</p>
        </div>
      </div>
      <div class="stepping" v-if="data.licenseRegisterAddress">
        <div class="p1">
          <p>营业执照注册地址</p>
        </div>
        <div class="p2">
          <p>{{ data.licenseRegisterAddress }}</p>
        </div>
      </div>
      <div class="stepping" v-if="data.businessLicense">
        <div class="p1">
          <p>营业执照注册号</p>
        </div>
        <div class="p2">
          <p>{{ data.businessLicense }}</p>
        </div>
      </div>
      <div class="stepping" v-if="data.licenseExpireStart">
        <div class="p1">
          <p>营业执照有效期</p>
        </div>
        <div class="p2">
          <p>
            {{
              data.licenseExpireStart && data.licenseExpire
                ? data.licenseExpireStart +
                  "至" +
                  expireFormate(data.licenseExpireStart, data.licenseExpire)
                : ""
            }}
          </p>
        </div>
      </div>
      <div class="stepping" v-if="data.businessLicenseImage">
        <div class="p1">
          <p>营业执照照片</p>
        </div>
        <div class="p2">
          <img :src="data.businessLicenseImage" alt="" />
        </div>
      </div>
      <div class="stepping" v-if="data.businessOperatorName">
        <div class="p1">
          <p>法人姓名</p>
        </div>
        <div class="p2">
          <p>{{ data.businessOperatorName }}</p>
        </div>
      </div>
      <div class="stepping" v-if="data.idcard">
        <div class="p1">
          <p>身份证号码</p>
        </div>
        <div class="p2">
          <p>{{ data.idcard }}</p>
        </div>
      </div>
      <div class="stepping" v-if="data.idcardValidStartDate">
        <div class="p1">
          <p>身份证有效期</p>
        </div>
        <div class="p2">
          <p>
            {{
              data.idcardValidStartDate && data.idcardValidEndDate
                ? "**** 至 ****"
                : ""
            }}
          </p>
        </div>
      </div>
      <p class="photograph" v-if="data.idcardImageFront">身份证照片</p>
      <div class="steppings" v-if="data.idcardImageFront">
        <div class="p1">
          <img :src="data.idcardImageFront" alt />
        </div>
        <div class="p2">
          <img :src="data.idcardImageBackground" alt />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import customHeader from "../../components/header/header.vue";
import StoreChoice from "../../components/StoreChoice/StoreChoice";
import Vue from "vue";

import { Toast, MessageBox } from "mint-ui";
import jsBridge from "../../tools/jsBridge";
import config from "../../base/profile/config.json";
import jsAuthority from "../../tools/jsAuthority.js";
import shopService from "../../js/shopService.js";
import moment from "moment";
import VueClipboard from "vue-clipboard2";
Vue.use(VueClipboard);
export default {
  name: "message",
  data() {
    return {
      store: [],
      list: {},
      data: {
        authEditShop: false,
        optionType: 1,
        storeName: "",
        shopLogo: "",
        dishType: "",
        storeImgList: [],
        shopId: "",
        contactNumber: "",
        address: "",
        desc: "",
        kbBindState: false,
        kbShopName: "",
        kbShopId: "",
        kbStauts: "正常",
        alipayState: false,
        wxPayState: false,
        unionPayState: false,
        auditStatus: null,
        auditStatusText: "",
        auditIsNotPass: false,
        auditDesc: "",
        shopType: "",
        shopTypeTitle: "",
        businessLicense: "",
        businessLicenseImage: "",
        idcard: "",
        idcardImageFront: "",
        idcardImageBackground: "",
        invitationCode: "",
        companyName: "",
        licenseExpireStart: "",
        licenseExpire: "",
        businessOperatorName: "",
      },
    };
  },
  components: {
    customHeader,
    StoreChoice,
  },
  methods: {
    //门店选择回调
    getSelectStoreValue(value, storeName) {
      console.log(value, storeName);
      this.ajax({
        url: `/newapp/shop/getShopDetail.do?shopId=${value[0].selectKey}&desensitization=true1`,
        type: "get",
        controlLoading: true,
      })
        .then((res) => {
          if (res.success) {
            var data = res.resultObject;
            if (data != null && JSON.stringify(data) != "{}") {
              this.bindData(data);
            } else {
              MessageBox.alert("门店信息不存在").then((action) => {
                this.$router.push({
                  path: "/storeManage",
                });
              });
            }
          }
        })
        .catch(function (err) {});
    },
    doCopy(content) {
      if (!content) {
        return;
      }
      this.$copyText(content).then(
        (e) => {
          Toast("复制成功");
        },
        (e) => {
          Toast("您的系统版本过低,请长按手动复制");
        }
      );
    },
    //跳转收款账户管理
    ToAccountManage() {
      this.$router.push({
        path: "/storeManage/gatheringManage",
        query: { shopId: this.shopId },
      });
    },
    changeMoment(date) {
      return moment(date).format("YYYY-MM-DD");
    },
    //返回
    handleBack() {
      var query = this.$route.query;

      var from = query.from;
      var fromMy = from && from == "my";
      if (fromMy) {
        jsBridge.closeWindow();
      } else {
        this.$router.back();
      }
    },
    expireFormate(start, deal) {
      const startDate = moment(start).format("YYYY-MM-DD");
      if (startDate && deal) {
        if (deal == "29991231") {
          return "长期";
        } else {
          return moment(startDate.replace(/-/g, "/"))
            .add(deal, "years")
            .format("YYYY-MM-DD");
        }
      }
      return;
    },
    //编辑
    opertation() {
      const shopId = this.shopId;
      const delFlag = this.$route.query.delFlag;
      // this.$router.push({ path: "/SMSVerification2", query: { linkToUrl:"editStore",shopId:shopId,delFlag: delFlag}});
      // return;
      this.verify(shopId, delFlag);
    },
    //脱敏校验
    verify(shopId, delFlag) {
      const url = `app/shop/isVerify.do?shopId=${this.shopId}`;
      this.ajax({
        url: url,
        type: "get",
        controlLoading: true,
      })
        .then((res) => {
          if (res.success == true) {
            this.$router.push({
              path: "/storeManage/editStore",
              query: { id: shopId, type: 2, delFlag: delFlag },
            });
          } else {
            this.$router.push({
              path: "/SMSVerification2",
              query: {
                linkToUrl: "/storeManage/editStore",
                shopId: shopId,
                type: 2,
                delFlag: delFlag,
              },
            });
          }
        })
        .catch((err) => {});
    },
    showImg: function (index) {
      try {
        jsBridge.viewPicture(
          { files: this.data.storeImgList, current: index },
          function (params) {}
        );
      } catch (e) {
        Toast("预览失败");
      }
    },
    bindData(data) {
      //绑定页面数据
      this.data = data;
      // this.shopId = data.shopId;
      //处理日期
      this.data.licenseExpireStart = this.changeMoment(
        this.data.licenseExpireStart
      );
      if (data.branchShopName != "" && data.branchShopName.length > 0) {
        this.data.storeName =
          data.mainShopName + "(" + data.branchShopName + ")";
      } else {
        this.data.storeName = data.mainShopName;
      }
      // //处理显示logo
      // if (data.mainImage && data.mainImage.length > 0) {
      //   this.data.shopLogo = data.mainImage[0];
      // }
      // var dishType = data.categoryLevel1;
      // if (data.categoryLevel2) {
      //   dishType = dishType + "/" + data.categoryLevel2;
      // }
      // if (data.categoryLevel3) {
      //   dishType = dishType + "/" + data.categoryLevel3;
      // }
      // this.data.dishType = dishType;

      //处理显示其他图放在一个list中
      var imgList = data.mainImage;

      if (!imgList) {
        imgList = [];
      }
      if (data.checkoutImage && data.checkoutImage[0]) {
        imgList = imgList.concat(data.checkoutImage);
      }

      if (data.innerImage) {
        imgList = imgList.concat(data.innerImage);
      }

      imgList = imgList.map((item) => {
        return CommonUtil.imgUrlFormate(item, config.previewUrlPrefix);
      });

      this.data.storeImgList = imgList;

      this.data.businessLicenseImage = CommonUtil.imgUrlFormate(
        this.data.businessLicenseImage,
        config.previewUrlPrefix
      );
      console.log(this.data.businessLicenseImage, "898");

      var idcardImage = data.idcardImage;
      console.log(data, "789");
      if (idcardImage) {
        this.data.idcardImageFront = CommonUtil.imgUrlFormate(
          idcardImage["A"],
          config.previewUrlPrefix
        );
        console.log(this.data.idcardImageFront, "00");
        this.data.idcardImageBackground = CommonUtil.imgUrlFormate(
          idcardImage["B"],
          config.previewUrlPrefix
        );
      }
      //收款渠道
      this.data.alipayState = data.alipayPayStatus === "1";
      this.data.wxPayState = data.wxPayStatus === "1";
      this.data.unionPayState = data.unionpay === "1";
      this.data.cloudPayState = data.cloudPayStatus === "1";
      //关联支付宝判断
      if (data.kbShopId && data.kbShopId != "") {
        this.data.kbBindState = true;
        this.data.kbStauts = data.alipayPayStatus === "1" ? "正常" : "异常";
      }
      this.data.headImg = CommonUtil.imgUrlFormate(
        data.mainImage[0],
        config.previewUrlPrefix
      );
      //审核状态
      this.data.auditStatusText = this.dictAuditStatus[data.auditStatus];
      //this.data.auditIsNotPass = shopService.getAuditIsNoPass(data.auditStatus);
      //审核区域
      this.data.shopTypeTitle = shopService.getShopTypeTitle(data.shopType);

      //===审核通过可修改修改
      var editFlag = shopService.getAuditIsEditShop(data.auditStatus);

      if (editFlag) {
        const _this = this;
        jsAuthority.checkedSuccess(function () {
          _this.data.authEditShop = jsAuthority.checked(
            "app.me.shopmanage.detail.edit"
          );
        });
      }
    },
  },
  computed: {
    formateStore() {
      let val = "";
      if (
        this.roleInfo.manyShopFlag !== undefined &&
        !this.roleInfo.manyShopFlag
      ) {
        this.store = [
          {
            selectName: this.roleInfo.shopName,
            selectKey: this.roleInfo.yzShopId,
          },
        ];
        val = this.roleInfo.shopName;
      } else if (!this.isAllStore) {
        if (this.store.length === 1) {
          val = this.store[0].selectName;
        } else {
          val = "已选择" + this.store.length + "家门店";
        }
      } else {
        val = "全部门店";
      }
      return val;
    },
  },
  mounted() {
    this.$refs.StoreChoice.popupShow();
  },
  created: function () {},
};
</script>

<style lang="scss" scoped>
@import "index.scss";
</style>